/**
 * \file
 *
 * \brief User board initialization template
 *
 */

#include <board.h>
#include <conf_board.h>

void board_init(void)
{
	/* This function is meant to contain board-specific initialization code
	 * for, e.g., the I/O pins. The initialization can rely on application-
	 * specific board configuration, found in conf_board.h.
	 */
	
	ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
	ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
	ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
	ioport_configure_pin(LED3_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
	
	ioport_configure_pin(DIP_SW1, IOPORT_DIR_INPUT | IOPORT_PULL_UP);
	ioport_configure_pin(DIP_SW2, IOPORT_DIR_INPUT | IOPORT_PULL_UP);
	
	ioport_configure_pin(RESET_INPUT_FPGA, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	ioport_configure_pin(RESET_LEFT_OUT_FPGA, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	ioport_configure_pin(RESET_RIGHT_OUT_FPGA, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	ioport_configure_pin(RESET_HDMI_RX, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	ioport_configure_pin(RESET_LEFT_W2, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	ioport_configure_pin(RESET_RIGHT_W2, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);

	
	// Configure DVI PWDN pins as input - It's used as I2C address bootstrap

	ioport_configure_pin(PWDN_LEFT_DVI, IOPORT_DIR_INPUT);
	ioport_configure_pin(PWDN_RIGHT_DVI, IOPORT_DIR_INPUT);
	
	delay_ms(500);
	
	// Place the DVI transmitters in power down mode
	ioport_configure_pin(PWDN_LEFT_DVI, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	ioport_configure_pin(PWDN_RIGHT_DVI, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	
	// Configure pins for console UART (USARTC0)
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTC, 2), IOPORT_DIR_INPUT);
	
	// Configure pins for WCU UART (USARTD0)
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 3), IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
	ioport_configure_pin(IOPORT_CREATE_PIN(PORTD, 2), IOPORT_DIR_INPUT);	
}
